﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using SharedGenomics.Core;
using SharedGenomics.Workbench.Core;
using SharedGenomics.Workbench.Messages;

namespace SharedGenomics.Workbench.Presenters
{
    /// <summary>
    /// A URI navigator that uses windows that are part of the application to display Web content.
    /// </summary>
    //TODO: move this?
    public class InternalUriNavigator : IUriNavigator
    {
        public InternalUriNavigator(IEventBroker eventBroker)
        {
            this.EventBroker = eventBroker;
        }

        public void Navigate(Uri target)
        {
            Action<WebBrowserPresenter> goToTargetAction = new Action<WebBrowserPresenter>((p) => p.Navigate(target));
            ShowPresenterMessage showMessage = new ShowPresenterMessage(FormDisplayMode.NonModalDialog, typeof(WebBrowserPresenter), goToTargetAction, null);
            this.EventBroker.Publish(showMessage);
        }

        private IEventBroker EventBroker { get; set; }

        #region IEventSubscriber<NavigateUriMessage> Members

        public void Receive(NavigateUriMessage message)
        {
            message.ThrowIfNull("message");
            this.Navigate(message.Uri);
        }

        #endregion
    }
}
